package com.fms.kccc.object;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;

public class ImageContent {
	private Long id;
	private String title;
	private String source;
	private String imageURL;
	private String smallImageURL;
	private String imageURLBackup;
	private String smallImageURLBackup;
	private String category;
	private Date createAt;
	private int errorNum;
	private int viewNum;
	private int likeNum;
	private int chap;
	public ImageContent() {
		super();
		this.errorNum = 0;
		this.viewNum = 0;
		this.createAt = new Date();
		this.likeNum = 0;
	}

	public ImageContent(String title, String source, String imageURL,
			String smallImageURL, String imageURLBackup,
			String smallImageURLBackup, String category) {
		this.title = title;
		this.source = source;
		this.imageURL = imageURL;
		this.smallImageURL = smallImageURL;
		this.imageURLBackup = imageURLBackup;
		this.smallImageURLBackup = smallImageURLBackup;
		this.category = category;
		this.createAt = new Date();
		this.errorNum = 0;
		this.viewNum = 0;
		this.likeNum = 0;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public String getImageURL() {
		return imageURL;
	}

	public void setImageURL(String imageURL) {
		this.imageURL = imageURL;
	}

	public String getSmallImageURL() {
		return smallImageURL;
	}

	public void setSmallImageURL(String smallImageURL) {
		this.smallImageURL = smallImageURL;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public Date getCreateAt() {
		return createAt;
	}

	public void setCreateAt(Date createAt) {
		this.createAt = createAt;
	}

	public int getErrorNum() {
		return errorNum;
	}

	public void setErrorNum(int errorNum) {
		this.errorNum = errorNum;
	}

	public int getViewNum() {
		return viewNum;
	}

	public void setViewNum(int viewNum) {
		this.viewNum = viewNum;
	}

	/*
	 * @PreUpdate
	 * 
	 * @PrePersist protected void increment() { viewNum = viewNum + 1; }
	 */

	public String getImageURLBackup() {
		return imageURLBackup;
	}

	public void setImageURLBackup(String imageURLBackup) {
		this.imageURLBackup = imageURLBackup;
	}

	public String getSmallImageURLBackup() {
		return smallImageURLBackup;
	}

	public void setSmallImageURLBackup(String smallImageURLBackup) {
		this.smallImageURLBackup = smallImageURLBackup;
	}

	public int getLikeNum() {
		return likeNum;
	}

	public void setLikeNum(int likeNum) {
		this.likeNum = likeNum;
	}

	public int getChap() {
		return chap;
	}

	public void setChap(int chap) {
		this.chap = chap;
	}

	public String toJson() {
		return new JSONSerializer().exclude("*.class").deepSerialize(this);
	}

	public static ImageContent fromJsonToImageContent(String json) {
		return new JSONDeserializer<ImageContent>().use(null,
				ImageContent.class).deserialize(json);
	}

	public static String toJsonArray(Collection<ImageContent> collection) {
		return new JSONSerializer().exclude("*.class")
				.deepSerialize(collection);
	}

	public static Collection<ImageContent> fromJsonArrayToImageContents(
			String json) {
		return new JSONDeserializer<List<ImageContent>>()
				.use(null, ArrayList.class).use("values", ImageContent.class)
				.deserialize(json);
	}
}
